/**
 * 通知服务
 * 统一的通知管理
 */
class NotificationService {
    /**
     * 显示通知消息
     * @param {string} message - 通知消息
     * @param {string} type - 通知类型 (success, error, warning, info)
     * @param {number} duration - 显示时长（毫秒）
     */
    static show(message, type = 'info', duration = 3000) {
        // 优先使用UX工具的通知
        if (window.uxUtils && window.uxUtils.showToast) {
            window.uxUtils.showToast(message, type);
            return;
        }
        
        // 使用自定义通知系统
        this.createCustomNotification(message, type, duration);
    }
    
    /**
     * 创建自定义通知
     */
    static createCustomNotification(message, type, duration) {
        const notification = document.createElement('div');
        const icons = {
            success: 'fas fa-check-circle',
            error: 'fas fa-exclamation-circle',
            warning: 'fas fa-exclamation-triangle',
            info: 'fas fa-info-circle'
        };
        
        const colors = {
            success: 'bg-green-500',
            error: 'bg-red-500',
            warning: 'bg-yellow-500',
            info: 'bg-blue-500'
        };
        
        notification.className = `fixed top-4 right-4 z-50 p-4 rounded-lg shadow-lg text-white ${colors[type]} transform transition-all duration-300 translate-x-full`;
        notification.innerHTML = `
            <div class="flex items-center">
                <i class="${icons[type]} mr-2"></i>
                <span>${message}</span>
                <button class="ml-4 text-white hover:text-gray-200" onclick="this.parentElement.parentElement.remove()">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        `;
        
        document.body.appendChild(notification);
        
        // 显示动画
        setTimeout(() => {
            notification.classList.remove('translate-x-full');
        }, 10);
        
        // 自动隐藏
        if (duration > 0) {
            setTimeout(() => {
                notification.classList.add('translate-x-full');
                setTimeout(() => {
                    if (notification.parentElement) {
                        notification.remove();
                    }
                }, 300);
            }, duration);
        }
    }
    
    /**
     * 显示成功通知
     */
    static success(message, duration = 2000) {
        this.show(message, 'success', duration);
    }
    
    /**
     * 显示错误通知
     */
    static error(message, duration = 5000) {
        this.show(message, 'error', duration);
    }
    
    /**
     * 显示警告通知
     */
    static warning(message, duration = 4000) {
        this.show(message, 'warning', duration);
    }
    
    /**
     * 显示信息通知
     */
    static info(message, duration = 3000) {
        this.show(message, 'info', duration);
    }
}

// 导出为全局变量
window.NotificationService = NotificationService;

// 添加模块就绪标记
window.NotificationService._isReady = true;
console.log('NotificationService模块已加载并就绪');